//
//  firstproductxqTableViewCell.m
//  BAOASystem
//
//  Created by michael on 2018/2/27.
//  Copyright © 2018年 czd. All rights reserved.
//

#import "firstproductxqTableViewCell.h"
#import "OALoginViewController.h"
@implementation firstproductxqTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
  _cyleView = [[xqcollectionviewfirst alloc]initWithFrame:CGRectMake(0, 0, KScreenWidth, 150)];
   [self.contentView addSubview:_cyleView];

 _label1 = [[UILabel alloc]init];
    _label1.frame = CGRectZero;
        _label1.numberOfLines = 0;
        _label1.textColor = [UIColor colorWithHexString:@"484848"];
      [_label1 setFont:[UIFont systemFontOfSize:13]];
       [self.contentView addSubview:_label1];
    
       _label2 = [[UILabel alloc]init];
    _label2.frame = CGRectZero;
    _label2.numberOfLines = 0;
    _label2.textColor = [UIColor colorWithHexString:@"a1a1a1"];
      [_label2 setFont:[UIFont systemFontOfSize:12]];
       [self.contentView addSubview:_label2];
    
       _label3 = [[UILabel alloc]init];
    _label3.frame = CGRectZero;
            _label3.numberOfLines = 0;

    _label3.textColor = [UIColor colorWithHexString:@"a1a1a1"];
      [_label3 setFont:[UIFont systemFontOfSize:12]];
       [self.contentView addSubview:_label3];
    
 _label4 = [[UILabel alloc]init];
         _label4.numberOfLines = 0;

    _label4.frame = CGRectZero;
        _label4.textColor = [UIColor colorWithHexString:@"a1a1a1"];

      [_label4 setFont:[UIFont systemFontOfSize:12]];
       [self.contentView addSubview:_label4];
_label5 = [[UILabel alloc]init];
    _label5.frame = CGRectZero;
             _label5.numberOfLines = 0;

            _label5.textColor = [UIColor colorWithHexString:@"a1a1a1"];

      [_label5 setFont:[UIFont systemFontOfSize:12]];
       [self.contentView addSubview:_label5];
_button  = [UIButton buttonWithType:UIButtonTypeCustom];
[_button setImage:[UIImage imageNamed:@"购物车图标"] forState:UIControlStateNormal];
[_button addTarget:self action:@selector(action) forControlEvents:UIControlEventTouchUpInside];
[self.contentView addSubview:_button];
//UIButton *backbutton = [UIButton buttonWithType:UIButtonTypeCustom];
//[backbutton setImage:[UIImage imageNamed:@"返回"] forState:UIControlStateNormal];
//[backbutton addTarget:self action:@selector(backaction) forControlEvents:UIControlEventTouchUpInside];
//[self.contentView addSubview:backbutton];

}

return self;

}
- (void)backaction{
[self.ViewController.navigationController popViewControllerAnimated:YES];
}
- (void)layoutSubviews
{
[super layoutSubviews];

_cyleView.data = _array;
[_cyleView.collectionView reloadData];
_label1.frame = CGRectMake(0, _cyleView.bottom, KScreenWidth, 32) ;
_label1.text = _dict[@"title"];
_label1.textAlignment = 1;
_button.frame = CGRectMake(KScreenWidth-40, 135, 30, 30);
_label2.frame = CGRectMake(10, _label1.bottom,( KScreenWidth-20)/2, 30);
_label2.text = [NSString stringWithFormat:@"%@:%@",NSLocalizedString(@"商品详情-产地", nil),_dict[@"sourceArea"]];
_label3.frame = CGRectMake(_label2.right, _label1.bottom,(KScreenWidth-20)/2, 30);
_label3.text = [NSString stringWithFormat:@"%@:%@",NSLocalizedString(@"商品详情-供货总量", nil),_dict[@"totals"]];
_label3.textAlignment = 2;

_label4.frame = CGRectMake(10, _label3.bottom,(KScreenWidth-20)/2-50, 30);
_label4.text = [NSString stringWithFormat:@"%@:%@",NSLocalizedString(@"商品详情-付款方式", nil),_dict[@"paymentMethod"]];
_label5.frame = CGRectMake(_label4.right, _label3.bottom,(KScreenWidth-20)/2+50, 30);
_label5.text = [NSString stringWithFormat:@"%@:%@",NSLocalizedString(@"商品详情-发货期", nil),_dict[@"days"]];
_label5.textAlignment = 2;


}
- (void)action{
   UIStoryboard * storyBoard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];


    if (![[[NSUserDefaults standardUserDefaults]objectForKey:@"autoLogin"]isEqualToString:@"Y"]&&![[DanLi sharedDanLi].stay isEqualToString:@"yes"]) {
      OALoginViewController * loginVC = [storyBoard instantiateViewControllerWithIdentifier:@"LoginVC"];
        UINavigationController * navVC = [[UINavigationController alloc]initWithRootViewController:loginVC];
        loginVC.navigationController.navigationBar.hidden = YES;
                 self.ViewController.view.window.rootViewController = navVC;

}else{
{
NSString *website = [[NSUserDefaults standardUserDefaults] objectForKey:@"website"];
NSString *userName = [[NSUserDefaults standardUserDefaults] objectForKey:@"userName"];
NSString *password = [[NSUserDefaults standardUserDefaults] objectForKey:@"password"];

   NSString *language = [[NSUserDefaults standardUserDefaults] objectForKey:@"language"];
NSString *uid = [[NSUserDefaults standardUserDefaults] objectForKey:@"uid"];
NSString *cpid = [[NSUserDefaults standardUserDefaults] objectForKey:@"cpid"];

NSString *bodyStr = [NSString stringWithFormat:@"<?xml version='1.0' encoding='UTF-8'?><message><header><userName>%@</userName><password>%@</password><website>%@</website><language>%@</language><type>%@</type></header><body><uid>%@</uid><cpid>%@</cpid><pid>%@</pid></body></message>",userName,password,website,language,BAtype,uid,cpid,_dict[@"id"]];
 bodyStr= [bodyStr URLEncodedString];
 NSArray * array = @[@{@"arg0":bodyStr}];
     NSString * path = [NSString stringWithFormat:@"%@%@",BAip,bCart];
 [HttpTools requestWithURL:path arrays:array method:@"addCart" success:^(id JSON) {
   NSLog(@"%@",JSON);

    [self.ViewController.view makeToast:JSON[@"msg"]];
//[_tableView reloadData];

 } failure:^(NSError *error) {

    }];

}

}



}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
